package com.yitiao.data_algorithms.leetcode.editor.cn;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

import java.util.Stack;

class MinimumAbsoluteDifferenceInBst{
    // 2022-08-10 17:50:36
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    Stack<Integer> temp = new Stack();
    int ans = 9999999;
    public int getMinimumDifference(TreeNode root) {
        temp.push(-9999999);
        dfs(root);
        return ans;
    }

    void dfs(TreeNode root){
        if (root == null)return;
        dfs(root.left);
        ans = Math.min(ans,root.val-temp.pop());
        temp.push(root.val);
        dfs(root.right);
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}